class Solution
{
public:
    int flipgame(vector<int> &fronts, vector<int> &backs)
    {
        unordered_set<int> excluded;
        int n = fronts.size();
        for (int i = 0; i < n; ++i)
        {
            if (fronts[i] == backs[i])
            {
                excluded.insert(fronts[i]);
            }
        }
        int result = INT_MAX;
        for (int i = 0; i < n; ++i)
        {
            if (!excluded.count(fronts[i]))
            {
                result = min(result, fronts[i]);
            }
            if (!excluded.count(backs[i]))
            {
                result = min(result, backs[i]);
            }
        }
        return result == INT_MAX ? 0 : result;
    }
};